/**
 * @author {Yuntao Zhou}
 * depend on setting_plugin.js,Util.js,calendar.js
 */
var NewsSettingMenu=function(newsObj,config,callback){
    this.newsObj = newsObj;
    //this.container = container[0] ? container : $(container);
    this.type='DEFAULT';
    this.config={
        settingContainer:$(document.body),
        className:'rtq-setting-plugin-black',
        width:170,
        autoBoxID:'AutoBox',
        curW:'All',
        isSaveRange:false,
        instval:'QS'
    };
    this.callback={
        onTitleChanged:null,//function(title,isAdd){}
        onLockChecked:null,//function(lock){}
        onHeadShowHide:null,//function(selected){}
        onDateRangeChecked:null//function(selected){}
    }
    if(config){
        $.extend(this.config,config);
    }
    if(callback){
        $.extend(this.callback,callback);
    }
    this.maxListCount=10;
    this.el = null;
    this.groupBox=null;
    this.chkAddSymbol=null;
    this.chkLock=null;
    this.chkRange=null;
    this.wlMenu=null;
    this.plMenu=null;
    this.slMenu=null;
    this.vlMenu=null;
    this._wmDisabled=null;
    this._vmDisabled=null;
    this._abDisabled=null;
    this.ctListScrollPN=null;
    this.$settingPanel=null;
    this._ctListScrollPNResize=false;
    this.settingPlugin=null;
    this.defViewData=[{
        txt: 'New View',
        val: 'cv_add',
        o: -2
    }, {
        type: "separator"
    }];
    this.moreDataWatchlist=null;
    this.moreDataView=null;
    this.moreDataViewMaxCount=20;
    this.wlTimer=null;
    this.html='<div class="news-settingpn"></div>';
    this.init();
};
NewsSettingMenu.prototype={
    init:function(){
        var self=this;
        this.el=$(this.html).appendTo(this.config.settingContainer);
        var settingGroupList=[{name: 'Display',id: 1}, {name: 'Window',id: 2}];
        this.groupBox = new Util.GroupBox(this.el, settingGroupList, {
            width: 170,
            groupBoxHeight: 250
        });
        var windowBoxBody=this.groupBox.getGroup(2).bd,
            disPlayBoxBody=this.groupBox.getGroup(1).bd,
//              wbHtml="",
            dbHtml="";
        //window box
        this.settingPlugin=new SettingPlugin(windowBoxBody,this.config,{
            onChangeTitle:function(title,isAdd){
                if (typeof self.callback.onTitleChanged == 'function') {
                    self.callback.onTitleChanged(title, isAdd);
                }
            },
            onCheckLock:function(lock){
                if (typeof self.callback.onLockChecked == 'function') {
                    self.callback.onLockChecked(lock);
                }
            },
            onShowHide:function(selected){
                if (typeof self.callback.onHeadShowHide == 'function') {
                    self.callback.onHeadShowHide(selected);
                }
            }
        });
        //display box
        dbHtml+='<div class="clearfix block-row" style="z-index:4;"><h4>Show by</h4><div class="rtq-news-setting-row"><a class="news-sp-radio rtn-radio-on '+(this.newsObj.symbolType=='single'?'':'rtn-radio-off')+'" value="single"></a><span>Security</span><input id="'+this.config.autoBoxID+'" class="qs-ui-ipt box autoBox" type="text"><span class="qs-ui-btn go btn-search">GO</span></div>';
        dbHtml+='<div class="rtq-news-setting-row"><a class="news-sp-radio rtn-radio-on '+(this.newsObj.symbolType=='watchlist'?'':'rtn-radio-off')+'" value="watchlist"></a><div class="wllist rtq-ddl rtq-ddl-black" style="z-index:3"><div class="rtq-ddl-ipt wl-ipt" readonly="readonly" val=""></div></div></div>';
        dbHtml+='<div class="rtq-news-setting-row"><a class="news-sp-radio rtn-radio-on '+(this.newsObj.symbolType=='all'?'':'rtn-radio-off')+'" value="all"></a>All News</div></div>';
        dbHtml+='<div class="clearfix block-row" style="z-index:3;"><h4>Range</h4><div class="rtq-news-setting-row"><div class="dateRange"><input type="text" readOnly=true class="qs-ui-ipt qs-news-date-input" value="'+QS_DateFormat.transMDYDate(this.newsObj.fromDate)+'"/><span class="rtc-ctrl-lb1">-</span><input readOnly=true type="text" class="qs-ui-ipt qs-news-date-input" value="'+QS_DateFormat.transMDYDate(this.newsObj.toDate)+'"/><a class="qs-ui-btn go btn-go">GO</a></div></div><div class="rtq-news-setting-row"><div class="chk-range"></div></div></div>';
        if (this.newsObj.profile.type==GB_NewsDataManager.DEFAULT_TYPE) {
            dbHtml += '<div class="clearfix block-row" style="z-index:2;"><h4>View</h4><div class="rtq-news-setting-row"><div class="vllist rtq-ddl rtq-ddl-black"><div class="rtq-ddl-ipt vl-ipt" readonly="readonly" val=""></div></div></div></div>';
        }else{
            dbHtml += '<div class="clearfix block-row" style="z-index:2;"><h4>Comment Type</h4><div class="rtq-news-setting-row"><div class="data"><ul class="comment-menu" idkey="sourcemenu" style="width:147px;"></ul></div></div>';
        }
        disPlayBoxBody.append(dbHtml);
        this.$showW=disPlayBoxBody.find('.wllist .rtq-ddl-ipt');
        this.$showV=disPlayBoxBody.find('.vllist .rtq-ddl-ipt');
        this.updateCurrentWl(this.config.curW);
        this._createChkRange();//create dateRange check
        
        if(this.newsObj.profile.type==GB_NewsDataManager.DEFAULT_TYPE){   
///            this._createViewData(this.newsObj.defaultTabList);
            this._createViewMenu();
        }else{
            this._createCommentTypeListMenu(GB_NewsDataManager.briefingViewList,this.newsObj.openedList);
        }
        this._bindEvent();//bind event
//      if(this.config.instval=='QS'){
//          QS_watchlistDataManager.getPortfolioList(function(o){
//               self._createWPMenu(o);
//          });   
//      }

    },
    _createChkRange:function(){
        var self=this;
        this.chkRange=new Util.ButtonGroup(this.el.find('.chk-range'), [{txt:'Save the date range',val:'rangeSave'}], {
            onClick: function(v, btn){
                if(typeof self.callback.onDateRangeChecked=='function'){
                    self.callback.onDateRangeChecked(btn.isSelected);
                }
                //self.newsObj.isSaveRange=btn.isSelected;
            }
        },{type:'checkbox'});
        if(this.config.isSaveRange){
            this.chkRange.btns['rangeSave'].select();
        }
    },
    _bindEvent:function(){
        var self=this;
        var timeoutObj;
        var delay=200;
        var $wlList=this.el.find('.wllist');
        var $slList=this.el.find('.sllist');
        var $vlList=this.el.find('.vllist');
        var $radio=this.el.find('.news-sp-radio');
        var $input=this.el.find('.autoBox');
        var $sbtn=this.el.find('.btn-search');
        var $dateInput=this.el.find('.qs-news-date-input');
        if(this.newsObj.symbolType=='single'){
            this.disableWatchlistMenu();
        }else if(this.newsObj.symbolType=='watchlist'){
            this.enableWatchlistMenu();
            this.disableAutoBox();
        }else{
            this.disableAutoBox();
            this.disableWatchlistMenu();
        }       
        this.el.unbind('.newsSetting');
        $wlList.bind('mouseover.newsSetting',function(e){
            clearTimeout(timeoutObj);
            timeoutObj=setTimeout(function(){
                if (!self._wmDisabled) {
                    QS_watchlistDataManager.getPortfolioList(function(o){
                        if (self.wlMenu) {
                            self.reBindWatchlistMenu(o);
                        }else {
                            self._createWPMenu(o);
                        }
                        self.wlMenu.show();
                    });
                }
            },delay);      
        }).bind('mouseout.newsSetting',function(e){
            clearTimeout(timeoutObj);
            timeoutObj=setTimeout(function(){           
                if (!self._wmDisabled) {
                    self.wlMenu.hide();
                }
            },delay);
        });
        
        
        $vlList.bind('mouseover.newsSetting',function(e){
            clearTimeout(timeoutObj);
            timeoutObj=setTimeout(function(){
                if (!self._vmDisabled) {
                    self.vlMenu.show();
                }
            },delay);      
        }).bind('mouseout.newsSetting',function(e){
            clearTimeout(timeoutObj);
            timeoutObj=setTimeout(function(){           
                if (!self._vmDisabled) {
                    self.vlMenu.hide();
                }
            },delay);
        });
        
        this.el.bind('click.newsSetting',function(e){
            var target=$(e.target);
            if (target.hasClass('news-sp-radio')) {
                $radio.addClass('rtn-radio-off');
                target.removeClass('rtn-radio-off');
                var symbolType=target.attr('value');
                if(symbolType=='all'){
                    $input.val('');
                    self.disableAutoBox();
                    self.disableWatchlistMenu();
                    self.$showW.text('Select Watchlist');
                    self.newsObj.changeSymbol(symbolType);
                }else if(symbolType=='single'){
                    self.enableAutoBox();
                    self.disableWatchlistMenu();
                    self.$showW.text('Select Watchlist');
                    self.newsObj.curW=null;
                }else{
                    $input.val('');
                    self.disableAutoBox();
                    self.enableWatchlistMenu();
                }
            }
            else if(target.hasClass('btn-search')){
                self.newsObj.acceptTicker($input.val());
            }else if(target.attr('menuItemStyle') == 'trigger') {//Briefing window
                target.toggleClass("rtq-chkbox_off");
                var val=target.attr('value');
                var isChecked=!target.hasClass('rtq-chkbox_off');
                self.changeState(val,isChecked);
                self.newsObj.openView(self.newsObj.currentViewID);              
            }else if(target.hasClass('btn-go')){
                var sdt=$dateInput.eq(0).data('date');
                var edt=$dateInput.eq(1).data('date');
                self.newsObj.changeDateRange(sdt,edt);                      
            }
        }); 
        this._bindCalendar($dateInput);
        if (this.newsObj.profile.type!=GB_NewsDataManager.DEFAULT_TYPE) {
            this.groupBox.getGroup(1).hd.bind("click.newsSetting", function(e){
                self.resizeCtList();
            });
        }
        GB_qsAutoCompleteBox.subscription(this.config.autoBoxID,function(data){
            self.newsObj.acceptTicker(data);
        },{needClear:true});                
    },
    resizeCtList:function(){
        var self=this;
        if (self.ctListScrollPN && !self._ctListScrollPNResize) {
            self.ctListScrollPN.reSize(null, 75);
            self._ctListScrollPNResize = true;
        }
    },
    _bindCalendar:function(dateInput){
        var self=this;
        dateInput.eq(0).data('date',QS_DateFormat.convertDate(this.newsObj.fromDate));
        dateInput.eq(1).data('date',QS_DateFormat.convertDate(this.newsObj.toDate));
        if(typeof QSCAL=='undefined'){
            var QSCAL = new Util.Calendar($('body'),{},{
            });
        }
        QSCAL.register(dateInput[0],function(date){
            var sdt=dateInput.eq(0).data('date');
            var edt=dateInput.eq(1).data('date');
            if (date.getTime() > edt.getTime()) {
                dateInput.eq(0).data('date',edt);
                dateInput.eq(1).data('date',date).val(QS_DateFormat.formatMDYDate(date));
            }else {
                dateInput.eq(0).data('date',date);
            }
            dateInput.eq(0).val(QS_DateFormat.formatMDYDate(dateInput.eq(0).data('date')));         
        });
        QSCAL.register(dateInput[1],function(date){
            var sdt=dateInput.eq(0).data('date');
            var edt=dateInput.eq(1).data('date');
            if(date.getTime()<sdt.getTime()){
                dateInput.eq(1).data('date',sdt);
                dateInput.eq(0).data('date',date).val(QS_DateFormat.formatMDYDate(date));
            }
            else{
                dateInput.eq(1).data('date',date);
            }
            dateInput.eq(1).val(QS_DateFormat.formatMDYDate(dateInput.eq(1).data('date')));  
        });
        dateInput.focus(function(e){
            if ($.browser.msie) {       // fixed the issue that hit backspace key will back the web page.
                document.body.focus();
            }
            QSCAL.show(e.target,$(e.target).data('date'));      
        });
    },
    selectSymbolTypeRadio:function(type){
        var $radio=this.el.find('.news-sp-radio');
        $radio.addClass('rtn-radio-off');
        if (type == 'single') {
            $radio.eq(0).removeClass('rtn-radio-off');
            this.enableAutoBox();
            this.disableWatchlistMenu();
        }else if(type=='watchlist'){
            $radio.eq(1).removeClass('rtn-radio-off');
            this.disableAutoBox();
            this.enableWatchlistMenu();
        }else{
            $radio.eq(3).removeClass('rtn-radio-off');
            this.disableAutoBox();
            this.disableWatchlistMenu();
        }
    },
    _createWPMenu:function(lst){
        var self=this;
        this.wlMenu = new Util.CascadeMenu(this.el.find('.wllist').eq(0), {autoHide:true, display:false}, [], {onClick:function(item){
            self._watchlistAction(item,'W',self.moreDataWatchlist);
            clearTimeout(self.wlTimer);
            self.wlTimer=setTimeout(function(){self.wlMenu.hide();},200);            
        }});
        this.reBindWatchlistMenu(lst);
    },
    _watchlistAction:function(item,type,moreData){
        var self = this;
        if (item.data.o != null && typeof item.data.o != 'undefined') {
            if (item.data.o == 3) {
                var cfg = {};
                if (type == 'P') {
                    cfg = {'Portfolio': moreData};
                }else if (type == 'W') {
                    cfg = {'Watchlist': moreData};
                }
                self.newsObj.openMoreWindow(cfg, function(el){
                    self._selectMenuItem(type,el.getAttribute('cmd'), el.innerText || el.textContent);
                });
            }else{
                this._selectMenuItem(type,item.data.val,item.data.txt);
            }   
        }
    },
    _selectMenuItem:function(type,val,txt){
        var $radio=this.el.find('.news-sp-radio');
        if(type=='W'){
            this.selectSymbolTypeRadio('watchlist');
            this.updateCurrentWl(txt);
            this.newsObj.changeSymbol('watchlist',null,val);
        }else{
            
        }
    },
    _createSourceListMenu:function(sourceList,sourceSelect){
        var self=this;
        var data=[],source,isCheck;
//      data.push({
//          txt:'All News',
//          val:'All news',
//          type:'checkbox',
//          checked:true
//      });
        for(var i=0;i<sourceList.length;i++){
            if(GB_NewsDataManager.inArray(sourceList[i].id,sourceSelect)>=0){
                isCheck=true;
            }else{
                isCheck=false;
            }
            source={
                txt:sourceList[i].txt,
                val:sourceList[i].Src,
                type: "checkbox",
                checked: isCheck
            };
            data.push(source);
        }
        this.slMenu=new Util.CascadeMenu(this.el.find('.sllist').eq(0),{autoHide:true, display:false},data,{onClick:function(item){
            self._sourceAction(item);
        }});
    },
    _sourceAction:function(item){
        if(item.data.val=='Allnews'){
            return;
        }else{
            this.newsObj.selectSource(item.data.val);
            //this.newsObj.searchNews();
        }
    },
    _createCommentTypeListMenu:function(sourceList,sourceSelect){
        this.ctListScrollPN=new Util.ScrollPanel(this.el.find('.data'),{showX:false});
        this._fillBriefingCommentTypeList(sourceList,sourceSelect);
    },
    _fillBriefingCommentTypeList:function(sourceList,sourceSelect){
        var ul=this.el.find('[idkey="sourcemenu"]');
        var arr=[],checked;
        if(sourceList.length==sourceSelect.length){
            checked=true;
        }
        var html='<li><a href="javascript:void(0)" class = "rtq-chkbox' + (checked ? '' : ' rtq-chkbox_off') + '" menuitemstyle="trigger" value="Allnews">All Comments</a></li>';
        var index,id,flag=false,count=0;
        for(var i=0;i<sourceList.length;i++){
            id=sourceList[i].vid;
            if(id==0){
                continue;
            }
            index=GB_NewsDataManager.inArray(id,sourceSelect);
            checked=index>=0?true:false;
            if (id >= 12) {
                count++;
                if (flag) {
                    arr[i] = '<li class="level3"><a parentValue="TradingCalls" href="javascript:void(0)" class = "rtq-chkbox' + (checked ? '' : ' rtq-chkbox_off') + '" menuitemstyle="trigger" value="' + sourceList[i].val + '" cat="' + sourceList[i].vid + '">' + sourceList[i].txt + '</a></li>';
                }
                else {
                    arr[i] = '<li class="level2"><a href="javascript:void(0)"  class = "rtq-chkbox' + (count !=4?'' : ' rtq-chkbox_off') + '" menuitemstyle="trigger" value="TradingCalls">Trading Calls</a></li><li class="level3"><a parentValue="TradingCalls" href="javascript:void(0)" class = "rtq-chkbox' + (checked ? '' : ' rtq-chkbox_off') + '" menuitemstyle="trigger" value="' + sourceList[i].val + '" cat="' + sourceList[i].vid + '">' + sourceList[i].txt + '</a></li>';
                    flag=true;
                }
            }
            else {
                arr[i] = '<li class="level2"><a href="javascript:void(0)" class = "rtq-chkbox' + (checked ? '' : ' rtq-chkbox_off') + '" menuitemstyle="trigger" value="' + sourceList[i].val + '" cat="' + sourceList[i].vid + '">' + sourceList[i].txt + '</a></li>';
            }
        }
        html+=arr.join('');
        ul[0].innerHTML=html;
    },
    changeSettingUI:function(key){
        var ul=this.el.find('[idkey="sourcemenu"]');
        var a=ul.find('[value='+key+']');
        a.removeClass('rtq-chkbox_off').addClass('rtq-chkbox_off');
        if (a.attr('parentValue') == 'TradingCalls') {
            ul.find('[value=TradingCalls]').removeClass('rtq-chkbox_off').addClass('rtq-chkbox_off');
        }else {
            ul.find('a').eq(0).removeClass('rtq-chkbox_off').addClass('rtq-chkbox_off')
        }
    },
    changeState:function(key,isChecked){
        var ul=this.el.find('[idkey="sourcemenu"]');
        var currentID=-1;
        if (key == 'Allnews') {
            var arr=ul.find('a');
            this.newsObj.openedList=[];
            arr.removeClass('rtq-chkbox_off').addClass('rtq-chkbox_off');
            if(isChecked){
                for(var i=0,l=GB_NewsDataManager.briefingViewList.length;i<l;i++){
                    this.newsObj.openedList.push(GB_NewsDataManager.briefingViewList[i].vid)
                }
                arr.removeClass('rtq-chkbox_off');
            }else{
                this.newsObj.openedList=[0];
            }
            currentID=0;
        }else if(key=='TradingCalls'){
            var arr=ul.find('[parentValue="TradingCalls"]');
            var a ,len=arr.length,id,index;
            for(var i=0;i<len;i++){
                a=arr.eq(i);
                a.removeClass('rtq-chkbox_off').addClass('rtq-chkbox_off');
                id=parseInt(a.attr('cat'),10);
                index=GB_NewsDataManager.inArray(id,this.newsObj.openedList);
                if(index>=0){
                    this.newsObj.openedList.splice(index,1);                    
                    if (this.newsObj.openedList.length == 1) {
                        currentID = this.newsObj.openedList[0];
                    }
                    else {
                        currentID = this.newsObj.openedList[index - 1];
                    }                                   
                }
                if(isChecked){
                    a.removeClass('rtq-chkbox_off');                    
                    currentID = id;
                    this.newsObj.openedList.push(id);
                }
            }
            //this.newsObj.openedList.sort(function(a,b){return a-b;});
            var root=ul.find('a').eq(0);
            root.removeClass('rtq-chkbox_off').addClass('rtq-chkbox_off');
            if(this.newsObj.openedList.length==GB_NewsDataManager.briefingViewList.length+1){
                root.removeClass('rtq-chkbox_off');
            }
        }else{
            var a=ul.find('[value='+key+']');
            var id=parseInt(a.attr('cat'),10);
            var index=GB_NewsDataManager.inArray(id,this.newsObj.openedList);
            if(index>=0){
                this.newsObj.openedList.splice(index,1);
                if(this.newsObj.openedList.length==1){
                    currentID=this.newsObj.openedList[0];
                }else{
                    currentID=this.newsObj.openedList[index-1];
                }
            }else{
                currentID=id;
                this.newsObj.openedList.push(id);
            }
            //this.newsObj.openedList.sort(function(a,b){return a-b;});
            var tradeRoot=ul.find('[value=TradingCalls]');
            tradeRoot.removeClass('rtq-chkbox_off');
            var arr=ul.find('[parentValue="TradingCalls"]');
            var flag=false;
            for(var i=0;i<arr.length;i++){
                if(arr.eq(i).hasClass('rtq-chkbox_off')){
                    flag=true;
                    break;
                }
            }
            if(flag){
                tradeRoot.addClass('rtq-chkbox_off');
            }
            var root=ul.find('a').eq(0);
            root.removeClass('rtq-chkbox_off').addClass('rtq-chkbox_off');
            if(this.newsObj.openedList.length==GB_NewsDataManager.briefingViewList.length){
                root.removeClass('rtq-chkbox_off');
            }
        }
        this.newsObj.currentViewID=currentID;
    },
    _createViewMenu:function(){
        var self = this;
        this.vlMenu = new Util.CascadeMenu(this.el.find(".vllist").eq(0), {
            autoHide: true,
            display: false
        }, null,{onClick:function(item){
            self._viewAction(item, self.moreDataView);
        }});
    },
    _viewAction:function(item,moreData){
        var self=this;
        if (item.data.o != null && typeof item.data.o != 'undefined') {
            if (item.data.o == 3) {
                self.newsObj.openMoreWindow({
                    'View': moreData
                }, function(el){
                    self.newsObj.openView(parseInt(el.getAttribute('cmd'),10),el.innerText || el.textContent);
                    self.enableViewMenu();
                }, [{
                    txt: 'Select',
                    val: '0'
                }, {
                    txt: 'Edit',
                    val: '1'
                }, {
                    txt: 'Delete',
                    val: '2'
                }], function(el, val){
                    var id = el.getAttribute('cmd');
                    var t = el.innerText || el.textContent;
                    self._selectViewItem(val, id, t);
                    //close more
                });
            }else{
                self._selectViewItem(item.data.o, item.data.val, item.parent?item.parent.data.txt:item.data.txt);
            }
        }
    },
    _selectViewItem:function(act, val, txt){
        var self=this;
        switch (act.toString()) {
            case '-2':
                GB_NewsCustomView.create(this.newsObj);
                break;
            case '0':
                this.newsObj.openView(val,txt);
                break;
            case '1':
                if (val < 1) {
                    return;
                }
                GB_NewsCustomView.edit(this.newsObj,val);
                break;
            case '2':
                if (val < 1) {
                    return;
                }
                GB_NewsCustomView.remove(this.newsObj,val);
                break;
        }
    },
    disableViewMenu:function(){
        this._vmDisabled=true;
        this.$showV.parent().addClass('rtq-ddl-disable');
    },
    enableViewMenu:function(){
        this._vmDisabled=false;
        this.$showV.parent().removeClass('rtq-ddl-disable');
    },
    disableWatchlistMenu:function(){//disable watchlist
        this._wmDisabled=true;
        this.$showW.parent().addClass('rtq-ddl-disable');     
    },
    enableWatchlistMenu:function(){//enable watchlist
        this._wmDisabled=false;
        this.$showW.parent().removeClass('rtq-ddl-disable');
    },
    disableAutoBox:function(){//disable autobox
        this._abDisabled=true;    
        this.el.find('.autoBox').attr('disabled',true).addClass('rtq-ddl-disable');
        this.el.find('.btn-search').addClass('rtq-ddl-disable');
    },
    enableAutoBox:function(){//enable autobox
        this._abDisabled=false;
        this.el.find('.autoBox').attr('disabled',false).removeClass('rtq-ddl-disable');
        this.el.find('.btn-search').removeClass('rtq-ddl-disable');
    },
    changeUIState:function(val,pVal,flag){
        this.slMenu.changeUIState(val,pVal,flag);
    },
    saveConfig:function(){
        return this.settingPlugin.saveConfig();
    },
    reBindWatchlistMenu:function(lst){
        var data = [];
        if (!lst || lst.length < 1) {
            wlData.push({txt:'No available',val:''},{type:"separator"});
        }
        else {
            for (var i = 0; i < lst.length; i++) {
                 data.push({txt:lst[i].Name,val:lst[i].PfId,o:0});
            }              
        }   
        this.moreDataWatchlist = [];
        for (var i in data) {
            if(data[i].o!=-2&&data[i].o!=3&&typeof data[i].o!='undefined'){
                this.moreDataWatchlist.push({
                    text: data[i].txt,
                    cmd: data[i].val
                });
            }           
        }
        var Data=data.slice(0, this.maxListCount+2)
        if(Data.length>2){
            Data.push({type:"separator"},{txt:'More...',val:-1,o:3});
        } 
        this.wlMenu.reBind(Data);
    },
    reBindViewMenu:function(o){
        var vData = [],count=0;;
        this.moreDataView = [];
        for (var i = 0; i < o.length; i++) {
            if (o[i].val == 'msview') {
                 vData.push({
                    txt: o[i].txt,
                    val: o[i].vid,
                    o: 0,
                    subMenu: [{
                        txt: 'Select',
                        selectable: true,
                        val: o[i].vid,
                        o: 0
                    }]
                 });
            }else if(o[i].val=='myview'){
                vData.push({
                    txt: o[i].txt,
                    val: o[i].vid,
                    o: 0,
                    subMenu: [{
                        txt: 'Select',
                        val: o[i].vid,
                        selectable: true,
                        o: 0
                    }, {
                        txt: 'Edit...',
                        val: o[i].vid,
                        selectable: true,
                        o: 1
                    }, {
                        txt: 'Delete',
                        val: o[i].vid,
                        selectable: true,
                        o: 2
                    }]
                });
                this.moreDataView.push({
                    text: o[i].txt,
                    cmd: o[i].vid
                });
                count++;
            }
        }
        if(count>this.moreDataViewMaxCount){
            vData=vData.slice(0,this.moreDataViewMaxCount);
        }
        vData = this.defViewData.concat(vData);
        if (vData.length != 0) {
            vData.push({
                type: "separator"
            }, {
                txt: 'More...',
                val: -1,
                o: 3
            });
        }
        this.vlMenu.reBind(vData);
    },
    updateCurrentWl:function(txt){
        if(txt){
            this.newsObj.curW=txt;
            this.$showW.text(this.newsObj.curW);
        }else{
            this.$showW.text('Select Watchlist');
        }
    },
    updateCurrentView:function(txt){
        this.$showV.text(txt);
    },
    clear:function(){
        var dateInput=this.el.find('.qs-news-date-input');
        QSCAL.unregister(dateInput[0]);
        QSCAL.unregister(dateInput[1]);
        this.el.unbind('.newsSetting');
        for(var p in this){
            if(!p || p == 'clear'){continue;}
            this[p] = null;
            delete this[p];
        }
    },
    changeDateRangeUI:function(s,e){
        var dateInput=this.el.find('.qs-news-date-input');
        if(s!=null){
            dateInput.eq(0).data('date',QS_DateFormat.convertDate(s));  
            dateInput.eq(0).val(QS_DateFormat.formatMDYDate(dateInput.eq(0).data('date')));
        }
        if(e!=null){
            dateInput.eq(1).data('date',QS_DateFormat.convertDate(e));
            dateInput.eq(1).val(QS_DateFormat.formatMDYDate(dateInput.eq(1).data('date')));
        }
    }
};
